package de.java.shortys.utils.swing;

import java.awt.Component;
import java.text.DateFormat;
import java.util.Calendar;
import java.util.Locale;

import javax.swing.BorderFactory;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

import de.java.shortys.utils.format.FormatUtils;

public class CalendarCellRenderer extends DefaultTableCellRenderer {

	private static final long serialVersionUID = 1L;

	public Locale locale;

	@Override
	public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
			int row, int column) {
		super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
		if (Calendar.class.isAssignableFrom(value.getClass())) {
			setText(FormatUtils.getCalendarOutput(locale, (Calendar) value, DateFormat.FULL));
			setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
		}

		return this;
	}

	public CalendarCellRenderer(Locale locale) {
		super();
		this.locale = locale;
	}
}
